$(document).ready(function() { 
    $('#new_archievement_block').click(function(event){
        if(!$('#new_archivement').length){
            $('#ico_new_archievement').attr("id","ico_new_confirm_archievement");
            $('#add_new_archievement').text("?! Isso mesmo que eu quero!");
            Awesomepeople.createNewAchievement();
        }else{
           
            Awesomepeople.postNewArchievement({
                sucess: function(response){
                    $("#new_archivement").css({
                        position :'absolute', 
                        right: 0
                    });
                    $("#right_achievement_ul").prepend(response);
                    $("#new_archivement").fadeOut('slow', function(){
                        $("#new_archivement").remove();
                    });
                    $('#ico_new_confirm_archievement').attr("id","ico_new_archievement");
                    $('#add_new_archievement').text("Quero conquistar algo novo!");
                    $(".col").height( $(document).height() );
                }
            });
        }
    });

    $('.right_achievement_li').live('click',function(event){
        var $this = $(this);
        if($(this).find('div.achievement_undone').length){
            var id = $(this).attr('value');
            Awesomepeople.finishAchievement({
                idArchievement: id, 
                sucess : function(){
                    $($this).fadeOut();
                    var doneAchievement = $($this)[0].outerHTML;
                    doneAchievement = doneAchievement.replace("right", 'left');
                    doneAchievement = doneAchievement.replace("_undone", '');
                     $("#left_achievement_ul").prepend(doneAchievement);
                     $(".col").height( $(document).height() );
                }
            });
        }
    });
//Awesomepeople.init();
	
});